#include <stdio.h>
#define MAX_SIZE 100000

int BinaySearch(int a[], int size, int k)
{
    int l = 0, r = size - 1;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (a[mid] == k)
        {
            return mid;
        }
        else if (a[mid] > k)
        {
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }
    return -1;
}

int main()
{

    printf("\n\n========================================================================\n\n");

    int a[MAX_SIZE] = {1, 3, 6, 9, 14, 20, 32, 45, 56, 98};
    int size, tmp, key;
    printf("输入数组大小：\n");
    scanf("%d", &size);
    printf("输入数组元素\n");
    for (int i = 0; i < size; i++)
    {
        scanf("%d", &tmp);
        a[i] = tmp;
    }
    printf("输入查询关键字：\n");
    scanf("%d", &key);

    int m = BinaySearch(a, size, key);
    printf("下标%d", m);

    printf("\n\n========================================================================\n\n");
}